home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1450.dms / var1450.adf / TrackdiskDevice / Example2.c < prev    next >
C/C++ Source or Header  |  1992-04-27  |  6KB  |  235 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Devices                 Amiga C Club       */
  7. /* Chapter: Trackdisk Device            Tulevagen 22       */
  8. /* File:    Example2.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-27                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20.  
  21.  
  22. /* This program demonstrates how you can check what went */
  23. /* wrong while you were using the Trackdisk Device. This */
  24. /* example will try to use drive DF3:, which most of us  */
  25. /* does not have, and thus we will receive an error      */
  26. /* message. (Well if you have four diskdrives connected  */
  27. /* to your Amiga there will not be any error message.)   */
  28.  
  29.  
  30.  
  31. #include <exec/types.h>        /* STRPTR           */
  32. #include <exec/ports.h>        /* struct Message   */
  33. #include <exec/nodes.h>        /* NT_MESSAGE       */
  34. #include <exec/errors.h>       /* IO Error         */
  35. #include <devices/trackdisk.h> /* Trackdisk Device */
  36.  
  37.  
  38.  
  39. /* Diskdrive: */
  40. #define DF0 0
  41. #define DF1 1
  42. #define DF2 2
  43. #define DF3 3
  44.  
  45.  
  46.  
  47. /* Declare a pointer to our reply port: */
  48. struct MsgPort *replymp;
  49.  
  50. /* Declare a pointer to a IOStdReq structure:      */
  51. /* (We do not use the extended IOExtTD structure.) */
  52. struct IOStdReq *req;
  53.  
  54. /* Store error messages in this: */
  55. BYTE error = TRUE;
  56.  
  57.  
  58.  
  59. /* Declare our functions: */
  60. void main();
  61. void clean_up( STRPTR text );
  62. void TrackdiskError( BYTE error );
  63.  
  64.  
  65.  
  66. void main()
  67. {
  68.   /* Get a reply port: */
  69.   replymp = (struct MsgPort *)
  70.     CreatePort( NULL, 0 );
  71.   if( !replymp )
  72.     clean_up( "Could not create the reply port!" );
  73.  
  74.  
  75.   /* Create an IOStdReq structure: */
  76.   req = (struct IOStdReq *)
  77.     CreateStdIO( replymp );
  78.   if( !req )
  79.     clean_up( "Could not create the IO!" );
  80.  
  81.  
  82.   /* Try to open the Trackdisk Device, unit DF3: */
  83.   error = OpenDevice( TD_NAME, DF3, req, 0 );
  84.   if( error )
  85.   {
  86.     /* Tell the user what went wrong: */
  87.     TrackdiskError( error );
  88.  
  89.     /* Clean up and quit: */
  90.     clean_up( "Could not open the Trackdisk Device!" );
  91.   }
  92.  
  93.  
  94.  
  95.   /* Well, err... it is a stupid example... */
  96.  
  97.  
  98.  
  99.   /* Clean up and quit: */
  100.   clean_up( "The End!" );
  101. }
  102.  
  103.  
  104.  
  105. /* Close and return everything that has been */
  106. /* opened and  allocated before we quit:     */
  107.  
  108. void clean_up( STRPTR text )
  109. {
  110.   /* Close the Trackdisk Device: */ 
  111.   if( !error )
  112.     CloseDevice( req );
  113.  
  114.   /* Delete the IOStdReq structure: */
  115.   if( req )
  116.     DeleteStdIO( req, sizeof( struct IOStdReq ) );
  117.  
  118.   /* Remove the replyport: */
  119.   if( replymp )
  120.     DeletePort( replymp);
  121.  
  122.   /* Print the message: */
  123.   printf( "%s\n", text );
  124.  
  125.   /* Quit: */
  126.   exit( 0 );
  127. }
  128.  
  129.  
  130.  
  131. /* TrackdiskError() will give the user some more information */
  132. /* about the error.                                          */
  133. /*                                                           */
  134. /* Synopsis: TrackdiskError( error );                        */
  135. /*                                                           */
  136. /* error:    (BYTE) Give this function the error value, and  */
  137. /*           it will give the user some more information     */
  138. /*           about the error.                                */
  139.  
  140. void TrackdiskError( BYTE error )
  141. {
  142.   /* The complete list of possible errors: */
  143.   switch( error )
  144.   {
  145.     case TDERR_NotSpecified:
  146.       printf( "Something, we do not know what, failed!\n" );
  147.       break;
  148.  
  149.     case TDERR_NoSecHdr:
  150.       printf( "Could not find a sector!\n" );
  151.       break;
  152.  
  153.     case TDERR_BadSecPreamble:
  154.       printf( "The sector is corrupted!\n" );
  155.       break;
  156.  
  157.     case TDERR_BadSecID:
  158.       printf( "Problems with identifying the sector!\n" );
  159.       break;
  160.  
  161.     case TDERR_BadHdrSum:
  162.       printf( "The header had incorrect checksum!\n" );
  163.       break;
  164.  
  165.     case TDERR_BadSecSum:
  166.       printf( "The sector had incorrect checksum!\n" );
  167.       break;
  168.  
  169.     case TDERR_TooFewSecs:
  170.       printf( "There are too few sectors!\n" );
  171.       break;
  172.  
  173.     case TDERR_BadSecHdr:
  174.       printf( "The sector's header is corrupted!\n" );
  175.       break;
  176.  
  177.     case TDERR_WriteProt:
  178.       printf( "The disk is write protected!\n" );
  179.       break;
  180.  
  181.     case TDERR_DiskChanged:
  182.       printf( "The user removed the disk!\n" );
  183.       break;
  184.  
  185.     case TDERR_SeekError:
  186.       printf( "Could not find track 0!\n" );
  187.       break;
  188.  
  189.     case TDERR_NoMem:
  190.       printf( "Not enough memory!\n" );
  191.       break;
  192.  
  193.     case TDERR_BadUnitNum:
  194.       printf( "Requested diskdrive does not exist!\n" );
  195.       break;
  196.  
  197.     case TDERR_BadDriveType:
  198.       printf( "The Trackdisk Device can not handle that diskdrive!\n" );
  199.       break;
  200.  
  201.     case TDERR_DriveInUse:
  202.       printf( "The requested diskdrive is already used by someone else!\n" );
  203.       break;
  204.  
  205.     case TDERR_PostReset:
  206.       printf( "Oh no! The user hit the reset buttons, we are going down!\n" );
  207.       break;
  208.  
  209.  
  210.     /* The standard device errors: */
  211.  
  212.     case IOERR_OPENFAIL:
  213.       printf( "Could not open the device!\n" );
  214.       break;
  215.  
  216.     case IOERR_ABORTED:
  217.       printf( "The request was aborted!\n" );
  218.       break;
  219.       
  220.     case IOERR_NOCMD:
  221.       printf( "Not a valid command! Not supported by the trackdisk device!\n" );
  222.       break;
  223.       
  224.     case IOERR_BADLENGTH:
  225.       printf( "Bad length or value!\n" );
  226.       break;
  227.  
  228.     default:
  229.       /* Unknown error value: */
  230.       printf( "What? Unknown error code!\n" );
  231.   }
  232. }
  233.  
  234.  
  235.